# coding:utf-8
# Project:pyinterface
# author:wj
# time:2022/12/30 17:53
# Email:1305137785@qq.com
from openpyxl import load_workbook
from tool.handle_path import test_data_dir

class HandleExcel:
    def __init__(self,file_name):
        self.wb = load_workbook(filename=file_name) #表
        # self.sheet = self.wb[sheet_name] # 表单
        #获取excel中所有的sheetname
        self.sheet_names = self.wb.sheetnames

    def __close_excel(self):
        self.wb.close()

    def get_data_cases(self,sheet_name):
        case_list = []
        sheet_obj = self.wb[sheet_name]
        data_list = list(sheet_obj.iter_rows(values_only=True))
        title = data_list[0]
        datas = data_list[1:]
        for case in datas:
            res = dict(zip(title, case))
            case_list.append(res)
        self.__close_excel()
        return case_list

if __name__ == '__main__':
    cl = HandleExcel(file_name=test_data_dir)
    res = cl.get_data_cases(sheet_name='login')
    print(type(res),res)
